package com.example.demoeasyexcelboot.constants;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author: FSL
 * @date: 2023/4/12
 * @description: 性别枚举类
 */
@RequiredArgsConstructor
@Getter
public enum GenderType {
    UNKNOWN(0,"未知"),
    MAIL(1,"男"),
    FEMALE(2,"女");

    private final Integer code;
    private final String desc;

    /**根据desc获取对应的枚举类对象*/
    public static GenderType getGenderType(String desc){
        return Arrays.stream(GenderType.values())
                .filter(genderType -> genderType.getDesc().equals(desc))
                .findFirst()
                .orElse(UNKNOWN);
    }

    /**根据code获取对应的枚举对象*/
    public static GenderType getGenderType(Integer code){
        return Arrays.stream(GenderType.values())
                .filter(genderType -> genderType.getCode().equals(code))
                .findFirst()
                .orElse(UNKNOWN);
    }

    /**获取性别枚举Map集合*/
    public static Map<Integer,String> genderTypeMap(){
        return Arrays.stream(GenderType.values())
                .collect(Collectors.toMap(GenderType::getCode,GenderType::getDesc));
    }
}
